import axios from 'axios'
import { title } from '@/../package.json'
import { COMPILE_TIME_FILE_PATH } from '../../constant'

export const useTitleConfig = () => {
  setTitle(title)
  axios
    .get(COMPILE_TIME_FILE_PATH)
    .then((res) => console.log(res.data.time))
    .catch(() => console.log('尚未在项目路径中找到"compileTime.json"找到文件，无法打印编译时间'))
}

export const setTitle = (_title: string) => {
  if (_title) {
    const { MODE } = (import.meta as any).env
    let env = ''
    if (MODE === 'development') env = '测试--'
    else if (MODE === 'pre') env = '预生产--'
    document.title = env + _title
  }
}
